package net.cloudsun.graph.puzzle;

/**
 * 逆序数
 * created at 17/11/2021
 *
 * @author 俞建波
 * <a href="mailto://yujianbo@chtwm.com">yujianbo@chtwm.com</a>
 * @since 1.0.0
 */
public class InversionNumber {

    public static int count(int[] array) {
        int count = 0;
        for (int i = 0; i < array.length - 1; i++) {
            for (int j = i + 1; j < array.length; j++) {
                if (array[i] > array[j]) {
                    count = count + 1;
                }
            }
        }
        return count;
    }
}
